import React, { Component } from 'react';
import { Table, Pagination, Modal } from 'antd'
import styles from './TableList.less'
import { connect } from 'dva'

@connect(({ login }) => ({
  login
}))

class BuyerTableList extends Component {



  render() {
    const { storeListItem, storeListTotal, loading } = this.props
    const { isAdmin } = this.props.login
    const columns = [
      {
        title: '商家名称',
        dataIndex: 'name',
        key: '2',
        width: "25%"
      },
      {
        title: '会员名称',
        dataIndex: 'consumerName',
        key: '3',
        width: "15%"
      },
      {
        title: '添加时间',
        dataIndex: 'createTime',
        key: '4',
        width: "20%"
      },
      {
        title: '消费金 ',
        dataIndex: 'money',
        key: '5',
        width: "15%",
        render: (text) => {
          return (
            <span>{text ? text : "0"}</span>
          )
        }
      },
      {
        title: '置顶',
        dataIndex: 'stick',
        key: '6',
        width: "5%",
        render: (text) => {
          return (
            <span>{text == 0 ? '否' : '是'}</span>
          )
        }
      },
      {
        title: '操作',
        dataIndex: 'record',
        key: '7',
        width: "30%",
        render: (text, record) => {
          return (
            <div className={styles.record}>
              {isAdmin ? <span onClick={() => this.props.onStick(record)}>{record.stick == 0 ? "置顶" : "取消置顶"}</span> : <span></span>}
              <span onClick={() => this.props.onLook(record, 0)}>查看</span>
              {isAdmin ? <span onClick={() => this.props.onLook(record, 1)}>编辑</span> : <span></span>}
              <span onClick={() => this.props.onGetDetails(record)}>资金明细</span>
            </div>
          )

        }
      },
    ];
    const rowSelection = {
      onChange: (selectedRowKeys, selectedRows) => {
        this.props.onHandleSelect(selectedRowKeys, selectedRows)
      },
    };
    return (
      <div className={styles.BuyerTableList}>
        <Table bordered
          rowSelection={rowSelection}
          columns={columns}
          dataSource={storeListItem}
          loading={loading}
          rowKey={record => record.id} />
        <Pagination defaultCurrent={1} total={storeListTotal ? Number(storeListTotal) : 1} onChange={this.props.onHandleChangePage} style={{ float: 'right', marginTop: '20px' }} />
      </div>
    );
  }
}

export default BuyerTableList;
